<?php

namespace App\Repository\Machine;

use App\Base\IRI;
use App\Entity\Machine\MachineStatus;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;

/**
 * @method MachineStatus|null find($id, $lockMode = null, $lockVersion = null)
 * @method MachineStatus|null findOneBy(array $criteria, array $orderBy = null)
 * @method MachineStatus[]    findAll()
 * @method MachineStatus[]    findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
 */
class MachineStatusRepository extends ServiceEntityRepository
{
    public function __construct(ManagerRegistry $registry)
    {
        parent::__construct($registry, MachineStatus::class);
    }

    public function get4Choice($isNum = false)
    {
        $data = $this->findAll();
        $choice = [];
        foreach ($data as $row) {
            $choice[] = [
                "id"=>$isNum?
                    $row->getId()
                    :
                    IRI::createIRIStringFromEntity(MachineStatus::class,$row->getId()),
//                    "/api_/machine_statuses/{$row->getId()}",
                "value"=>$row->getName(),
            ];
        }
        return $choice;
    }
    // /**
    //  * @return MachineStatus[] Returns an array of MachineStatus objects
    //  */
    /*
    public function findByExampleField($value)
    {
        return $this->createQueryBuilder('m')
            ->andWhere('m.exampleField = :val')
            ->setParameter('val', $value)
            ->orderBy('m.id', 'ASC')
            ->setMaxResults(10)
            ->getQuery()
            ->getResult()
        ;
    }
    */

    /*
    public function findOneBySomeField($value): ?MachineStatus
    {
        return $this->createQueryBuilder('m')
            ->andWhere('m.exampleField = :val')
            ->setParameter('val', $value)
            ->getQuery()
            ->getOneOrNullResult()
        ;
    }
    */
}
